// 统一封装接口方法，每个方法负责请求一个url地址
// 逻辑页面只要导入这个接口方法，就可以发请求
// 可以统一管理

import request from '@/utils/request.js'
import {
  getToken
} from '@/utils/token'

// 既引入也同时向外导出
export * from './articleDetail.js'
export * from './login.js'
export * from './search.js'
export * from './user.js'

// 频道 - 获取所有频道
export const getAllChannelsAPI = () => request({
  url: '/v1_0/channels',
  method: 'GET'
})

// 频道 - 获取用户的频道（用户没登录，返回默认列表）
export const getUserChannelsAPI = () => request({
  url: '/v1_0/user/channels',
  method: 'GET',
  headers: {
    Authorization: `Bearer ${getToken()}`
  }
})

// 频道 - 更新用户的频道
export const updateUserChannelsAPI = ({
  channels
}) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels
  }
})

// 频道 - 文章 - 获取文章列表
export const getArticleListAPI = ({ channel_id, timestamp }) => request({
  url: '/v1_0/articles',
  method: 'GET',
  params: {
    channel_id,
    timestamp
  }
})

// 频道 -文章 - 不感兴趣反馈
export const articleDislikeAPI = (target) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  headers: {
    Authorization: `Bearer ${getToken()}`
  },
  data: {
    target
  }

})

// 频道 -文章 - 举报反馈
export const articleReportAPI = (target, type, remark) => request({
  url: '/v1_0/article/reports',
  method: 'POST',
  headers: {
    Authorization: `Bearer ${getToken()}`
  },
  data: {
    target,
    type,
    remark
  }
})
